using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.Utilities;
using System.IO;
using Microsoft.Build.Framework;

namespace BizTalk.BuildGenerator.Tasks.BRE
{
    /// <summary>
    /// Task to ackup the BRE
    /// </summary>
    public class BackupBRE : BaseBRETask 
    {
        private string _FolderPath;
               
        /// <summary>
        /// Task execute method
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            if (!Directory.Exists(this._FolderPath))
                throw new ApplicationException("The folder does not exist");

            string folder = Path.GetFullPath(this._FolderPath);
            Console.WriteLine("Backup Folder: " + folder);
            string filePath = folder + @"\" + Guid.NewGuid().ToString();
            BREManager mgr = base.CreateManager();
            mgr.ExportAll(filePath);
            return true;
        }
        /// <summary>
        /// This is the folder where the backup will be created
        /// </summary>
        [Required]
        public string FolderPath
        {
            get { return _FolderPath; }
            set { _FolderPath = value; }
        }        
    }
}
